Framework

Holds items within a grid layout.

Inventories are an object that contains Items in a grid layout. Every Character will have exactly one inventory attached to it, which is the only inventory that is allowed to hold bags - any item that has its own inventory (i.e a suitcase). Inventories can be owned by a character, or it can be individually interacted with as a standalone object. For example, the container plugin attaches inventories to props, allowing for items to be stored outside of any character inventories and remain "in the world".

You may be looking for the following common functions:

add Which adds an item to the inventory.

getItems Which gets all of the items inside the inventory.

getID Which gets the inventory's ID.

hasItem Which checks if the inventory has an item.

Functions

inventoryMeta:__eq(other)

Checks if two inventories are equal based on their IDs.

Parameters

  • other Inventory

    The other inventory to compare with.

Returns

  • bool

    Returns true if the inventories have the same ID, otherwise false.

inventoryMeta:__tostring()

Returns a string representation of the inventory.

Returns

  • string

    A string representation of the inventory, including its class name and ID.

inventoryMeta:add(item)

Alias for addItem function.

Parameters

  • item Item

    The item to add to the inventory.

Returns

  • Inventory

    Returns the inventory itself.

inventoryMeta:addAccessRule(rule, priority)

Adds an access rule to the inventory.

Parameters

  • rule function

    The access rule function.

  • priority number optional

    The priority of the access rule.

Returns

  • Inventory

    Returns the inventory itself.

inventoryMeta:addDataProxy(key, onChange)

Adds a data proxy to the inventory for a specified key.

Parameters

  • key any

    The key for the data proxy.

  • onChange function

    The function to call when the data associated with the key changes.

inventoryMeta:addItem(item, noReplicate)

Adds an item to the inventory.

Parameters

  • item item

    to add to the inventory.

  • noReplicate Boolean

    Set to true to prevent OnItemAdded to be called on the added item.

Returns

  • Inventory

    Returns the inventory itself.

inventoryMeta:canAccess(action, context)

Checks if a certain action is permitted for the inventory.

Parameters

  • action string

    The action to check for access.

  • context table optional

    Additional context for the access check.

Returns

  • bool or nil

    Returns true if the action is permitted, false if denied, or nil if not applicable.

  • string

    A reason for the access result.

inventoryMeta:configure()

Configures the inventory.

inventoryMeta:delete()

Deletes the inventory.

inventoryMeta:destroy()

Destroys the inventory and its associated items.

inventoryMeta:extend(className)

Extends the inventory to create a subclass with a specified class name.

Parameters

  • className string

    The name of the subclass.

Returns

  • table

    A subclass of the Inventory class.

inventoryMeta:getData(key, default)

Retrieves data associated with a specified key from the inventory.

Parameters

  • key String

    The key for the data.

  • default optional

    The default value to return if the key does not exist.

Returns

  • any

    The value associated with the key, or the default value if the key does not exist.

inventoryMeta:getFirstItemOfType(itemType)

Retrieves the first item of a specific type from the inventory.

Parameters

  • itemType string

    The type of item to retrieve.

Returns

  • table or nil

    The first item of the specified type, or nil if not found.

inventoryMeta:getID()

Retrieves the ID of the inventory.

Returns

  • any

    The ID of the inventory.

inventoryMeta:getItemCount(itemType)

Retrieves the total count of items in the inventory, optionally filtered by item type.

Parameters

  • itemType string optional

    The type of item to count. If nil, counts all items.

Returns

  • number

    The total count of items in the inventory, optionally filtered by item type.

inventoryMeta:getItems()

Retrieves all items in the inventory.

Returns

  • table

    An array containing all items in the inventory.

inventoryMeta:getItemsByUniqueID(uniqueID, onlyMain)

Retrieves items with a specified unique ID from the inventory.

Parameters

  • uniqueID string

    The unique ID of the items to retrieve.

  • onlyMain bool default: false

    Whether to retrieve only main items.

Returns

  • table

    An array containing the items with the specified unique ID.

inventoryMeta:getItemsOfType(itemType)

Retrieves items of a specific type from the inventory.

Parameters

  • itemType string

    The type of items to retrieve.

Returns

  • table

    An array containing items of the specified type.

inventoryMeta:getRecipients()

Retrieves the recipients for synchronization.

Returns

  • table

    An array containing the recipients for synchronization.

inventoryMeta:getType()

Retrieves the type of the inventory.

Returns

  • table

    The type of the inventory.

inventoryMeta:hasItem(itemType)

Checks if the inventory contains an item of a specific type.

Parameters

  • itemType string

    The type of item to check for.

Returns

  • bool

    Returns true if the inventory contains an item of the specified type, otherwise false.

inventoryMeta:initializeStorage(initialData)

Initializes the storage for the inventory.

Parameters

  • initialData table

    Initial data for the inventory.

Returns

  • Deferred

    A deferred promise.

inventoryMeta:instance(initialData)

Instantiates a new inventory instance.

Parameters

  • initialData table

    Initial data for the inventory instance.

Returns

  • Inventory

    The newly instantiated inventory instance.

inventoryMeta:loadItems()

Loads items from the database into the inventory.

Returns

  • Deferred

    A deferred promise.

inventoryMeta:new()

Creates a new instance of the inventory.

Returns

  • table

    A new instance of the Inventory class.

Example Usage

local newInventory = Inventory:new()

inventoryMeta:onDataChanged(key, oldValue, newValue)

Callback function called when data associated with a key changes.

Parameters

  • key any

    The key whose data has changed.

  • oldValue

    The old value of the data.

  • newValue

    The new value of the data.

inventoryMeta:onInstanced()

Initializes an instance of the inventory.

inventoryMeta:onItemsLoaded()

Callback function called when items are loaded into the inventory.

inventoryMeta:onLoaded()

Callback function called when the inventory is loaded.

inventoryMeta:register(typeID)

Registers the inventory with a specified type ID.

Parameters

  • typeID string

    The type ID to register the inventory with.

Example Usage

inventory:register("grid")

See Also

inventoryMeta:remove(itemID)

Alias for removeItem function.

Parameters

  • itemID

inventoryMeta:removeAccessRule(rule)

Removes an access rule from the inventory.

Parameters

  • rule function

    The access rule function to remove.

Returns

  • Inventory

    Returns the inventory itself.

inventoryMeta:removeItem(itemID, preserveItem)

Removes an item from the inventory.

Parameters

  • itemID number

    The ID of the item to remove.

  • preserveItem Boolean optional

    Whether to preserve the item's data in the database.

Returns

  • Deferred

    A deferred promise.

inventoryMeta:setData(key, value)

Sets data associated with a key in the inventory.

Parameters

  • key any

    The key to associate the data with.

  • value

    The value to set for the key.

Returns

  • Inventory

    Returns the inventory itself.

inventoryMeta:show(parent)

Displays the inventory UI to the specified parent element.

Parameters

  • parent any optional

    The parent element to which the inventory UI will be displayed.

Returns

inventoryMeta:sync(recipients)

Synchronizes the inventory with clients.

Parameters

  • recipients table optional

    The recipients to synchronize with.

inventoryMeta:syncData(key, recipients)

Synchronizes data changes with clients.

Parameters

  • key any

    The key whose data has changed.

  • recipients table optional

    The recipients to synchronize with.

inventoryMeta:syncItemAdded(item)

Synchronizes the addition of an item with clients.

Parameters

  • item Item

    The item being added.